package com.neulogistics.contrib.warehouse.api.application.converter;

import cn.hutool.json.JSONUtil;
import com.neulogistics.contrib.warehouse.api.application.query.WarehouseQuery;
import com.neulogistics.contrib.warehouse.infrastructure.persistence.orm.po.WarehousePO;
import org.springframework.beans.BeanUtils;

public class WarehouseQueryPOConverter {
    public static WarehousePO queryToPO(WarehouseQuery warehouseQuery){
        if(warehouseQuery == null){
            return null;
        }

        WarehousePO warehousePO = new WarehousePO();

        BeanUtils.copyProperties(warehouseQuery, warehousePO);
        if(warehouseQuery.getWarehouseAddress() != null)
            warehousePO.setWarehouseAddress(JSONUtil.parseObj(warehouseQuery.getWarehouseAddress()));

        if(warehouseQuery.getWarehouseLevel() == -1){
            warehousePO.setWarehouseLevel(null);
        }

        return warehousePO;
    }
}
